//
//  NSData+TYJSONSerialization.m
//  TYFoundation
//
//  Created by 郭艺伟 on 2019/2/28.
//

#import "NSData+TYJSONSerialization.h"

@implementation NSData (TYJSONSerialization)

- (id)ty_jsonValue {
    return [self ty_jsonValueWithError:nil];
}

- (id)ty_jsonValueWithError:(NSError * __autoreleasing *)error {
    
    return [self ty_jsonValueWithOptions:NSJSONReadingMutableContainers error:error];
}

- (id)ty_jsonValueWithOptions:(NSJSONReadingOptions)options error:(NSError * __autoreleasing *)error {
    
    if ([self length] == 0) {
        return nil;
    }
    
    NSError *errorT = nil;
    id jsonObj = [NSJSONSerialization JSONObjectWithData:self options:options error:&errorT];
    if (errorT) {
        if (error) {
            *error = errorT;
        }
        return nil;
    }
    
    return jsonObj;
}

@end
